package com.etc.service.impl;

import java.util.List;
import com.etc.dao.SinggerDao;
import com.etc.dao.impl.SinggerDaoImpl;
import com.etc.entity.PageInfo;
import com.etc.entity.Singger;
import com.etc.service.SinggerService;

public class SinggerServiceImpl implements SinggerService {
	private SinggerDao SinggerDao = new SinggerDaoImpl();
	
	@Override
	public List<Singger> findSinggerByCondition(Integer userId) {
		return SinggerDao.findByUserId(userId);
	}
	
	@Override
	public PageInfo<Singger> findSinggerByCondition(String initials, String regionName, String gender, String styleName,int pageNum,int pageSize) {
		// TODO Auto-generated method stub
		// 调用dao层获取分页结果集
		if("热门".equals(initials)) {
			initials = "";
		}
		if("全部".equals(regionName)) {
			regionName = "";
		}
		if("全部".equals(gender)) {
			gender = "";
		}
		if("全部".equals(styleName)) {
			styleName = "";
		}
				List<Singger> data = SinggerDao.findByCondition(initials, regionName, gender, styleName, pageNum, pageSize);
				
				// 调用dao层获取分页之前的总记录数
				Integer total = SinggerDao.countByCondition(initials, regionName, gender, styleName);
				
				// 构建PageInfo对象
				PageInfo<Singger> pageInfo = new PageInfo<Singger>(data, pageNum, pageSize, total);
				
				return pageInfo;
		
	}
	// ============================================ admin 操作  Service ======================================
	@Override
	public boolean addSinger(Singger singger) {
		int n = SinggerDao.addSinger(singger);
		return n > 0 ? true : false;
	}
	@Override
	public boolean deleteSingerById(Integer singgerId) {
		int n = SinggerDao.deleteSingerById(singgerId);
		return n > 0 ? true : false;
	}
	@Override
	public Singger getSingerInfoById(Integer singgerId) {
		return SinggerDao.findSingerInfoById(singgerId);
	}
	@Override
	public PageInfo<Singger> getSingerInfoBySingerName(String singgerName, int pageNum, int pageSize) {
		List<Singger> data = SinggerDao.findSingerInfoBySingerName(singgerName, pageNum, pageSize);
		Integer total = SinggerDao.countBySingerName(singgerName);
		PageInfo<Singger> pageInfo = new PageInfo<Singger>(data, pageNum, pageSize, total);
		return pageInfo;
	}
	@Override
	public boolean modifySingerInfo(Singger singger) {
		int n = SinggerDao.modifySingerInfo(singger);
		return n > 0 ? true : false;
	}

	@Override
	public List<Singger> exportAllSingerInfo() {
		return SinggerDao.findAll();
	}
	
	
}